# import tushare as ts
import pandas as pd
# import matplotlib.pyplot as plt
import mplfinance as mpf
# import matplotlib.dates as mdates
# import datetime as dt
# import numpy as np
# import time
# df = ts.get_hist_data('603833')
# df = pd.read_csv("history.csv", index_col="date")
df = pd.read_csv("oppeinhistory.csv", parse_dates=True, index_col="date")
df = df.iloc[::-1]
df = df[['open', 'high', 'low', 'close', 'volume']].rename(
    columns={
        'open': 'Open',
        'high': 'High',
        'low': 'Low',
        'close': 'Close',
        'volume': 'Volume'
    })
# print(df.head())
# quit()

# df[["open", "high", "close", "low"]].plot()
# df["date"].apply(mdates.date2num).astype('float')

# df["date_t"] = pd.to_datetime(df["date"])
# df["date_t"] = pd.to_numeric(df["date"])

# 将字符串时间数据转成浮点数
# df['date_t'] = df['date'].map(
#     lambda d: mdates.date2num(dt.datetime.strptime(d, "%Y-%m-%d")))

# df["date_t"] = df["date_t"].astype(np.float)

# print(df[["open", "high", "close", "low"]].describe())
# plt.show()

# tuples = [
#     tuple(x) for x in df[["date_t", "open", "high", "low", "close"]].values
# ]

# fig, ax = plt.subplots()
# ax.xaxis_date()
# ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d"))
# plt.xticks(rotation=45)
# plt.xlabel("Date")
# plt.ylabel("Price")
# plt.title("oppein")
# mplfinance.candlestick_ohlc(ax, tuples, width=.6, colorup='g', alpha=.4)
# mpf.plot(ax, tuples, width=.6, colorup='g', alpha=.4)
mpf.plot(df, type="candle", mav=(3, 6, 9), volume=True)
# plt.show()
# mpf.show()
